
const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
const rimraf = require('rimraf');

// 配置参考一位同学的Github笔记: https://github.com/iamflowerdog/learn-webpack-geekbang/blob/master/webpack.dll.js
// 上面的没用, 需要添加 : context: path.join(__dirname, 'build/library'),

module.exports = {
    entry: {
        library: [
            'react',
            'react-dom'
        ]
    },
    output: {
        path: path.join(__dirname, '/build/library'),
        filename: '[name]_[hash].dll.js',
        library: '[name]_[hash]'
    },
    plugins: [
        new webpack.DllPlugin({
            context: path.join(__dirname, 'build/library'),
            name: '[name]_[hash]',
            path: path.join(__dirname, 'build/library/[name].json')
        }),
        function CleanBuildDirectory(){
            // console.log('===CleanBuildDirectory===');
            // 2020年4月27日, 这样写不保险啊! 能确保这个插件一定先执行吗?
            const buildDir = path.join(__dirname, 'build/library');
            rimraf(buildDir, (err) => {
                console.log(buildDir);
            });
        },
    ]
};
